/*
 *    Copyright 2011-2012 The Hook Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.hook.yaksha.config;

import org.hook.yaksha.AnalysisConstants;

import org.apache.commons.lang.StringUtils;

/**
 * 任务的配置类
 * 
 * @author suwuqiang 2011-12-26
 */
public class JobConfig extends AbstractConfig {
	private static final long serialVersionUID = -1824935049820114759L;
	private final static String REPORT_CONFIGS = "reportConfigs";
	private final static String INPUT = "input";
	private final static String OUTPUT = "output";
	private final static String SPLITREGEX = "splitRegex";
	private final static String INPUT_ENCODING = "inputEncoding";
	private final static String OUTPUT_ENCODING = "outputEncoding";
	private final static String INPUT_PARAMS = "inputParams";
	private final static String OUTPUT_PARAMS = "outputParams";
	private final static String TASK_RECYCLE_TIME = "taskRecycleTime";
	private final static String JOB_RESET_TIME = "jobResetTime";
	private final static String REPORT_PERIOD_DEFINE = "reportPeriodDefine";

	/**
	 * 任务组重置时间，单位(秒)
	 * 
	 * @return 任务组重置时间(默认10分钟)
	 */
	public int getJobResetTime() {
		if (this.properties.containsKey(JOB_RESET_TIME))
			return Integer.parseInt((String) this.properties.get(JOB_RESET_TIME));
		return 10 * 60;
	}

	/**
	 * 设置任务组重置时间，单位(秒)
	 * 
	 * @param jobResetTime
	 */
	public void setJobResetTime(String jobResetTime) {
		this.properties.put(JOB_RESET_TIME, jobResetTime);
	}

	/**
	 * 单个任务重置时间，单位(秒)，多久时间没有被执行完毕任务可以被回收再分配
	 * 
	 * @return 单个任务重置时间(默认1分钟)
	 */
	public int getTaskRecycleTime() {
		if (this.properties.containsKey(TASK_RECYCLE_TIME))
			return Integer.parseInt((String) this.properties.get(TASK_RECYCLE_TIME));
		return 60;
	}

	/**
	 * 设置单个任务重置时间，单位(秒)
	 * 
	 * @param taskRecycleTime
	 */
	public void setTaskRecycleTime(String taskRecycleTime) {
		this.properties.put(TASK_RECYCLE_TIME, taskRecycleTime);
	}

	/**
	 * 报表配置文件，模型配置，用于建立job的统计规则
	 * 
	 * @return 规则数组
	 */
	public String[] getReportConfigs() {
		if (this.properties.containsKey(REPORT_CONFIGS))
			return StringUtils.split((String) this.properties.get(REPORT_CONFIGS), ",");
		return null;
	}

	/**
	 * 设置报表配置文件，模型配置
	 * 
	 * @param reportConfigs
	 */
	public void setReportConfigs(String reportConfigs) {
		this.properties.put(REPORT_CONFIGS, reportConfigs);
	}

	/**
	 * 报表有效时间段，用于增量报表，支持day,hour,month，默认是day，也就是一天重置一次增量报表
	 * 
	 * @return 报表有效时间段
	 */
	public String getReportPeriodDefine() {
		if (this.properties.containsKey(REPORT_PERIOD_DEFINE))
			return (String) this.properties.get(REPORT_PERIOD_DEFINE);
		return AnalysisConstants.REPORT_PERIOD_DAY;
	}

	/**
	 * 设置报表有效时间段
	 * 
	 * @param reportPeriodDefine
	 */
	public void setReportPeriodDefine(String reportPeriodDefine) {
		this.properties.put(REPORT_PERIOD_DEFINE, reportPeriodDefine);
	}

	/**
	 * 分析内容输入目录
	 * 
	 * @return 输入目录
	 */
	public String getInput() {
		return (String) this.properties.get(INPUT);
	}

	/**
	 * 设置分析内容输入目录
	 * 
	 * @param input
	 */
	public void setInput(String input) {
		this.properties.put(INPUT, input);
	}

	/**
	 * 分析结果输出目录，xxx:xxxx用冒号作为协议与具体位置的分割
	 * 
	 * @return 分析结果输出目录
	 */
	public String getOutput() {
		return (String) this.properties.get(OUTPUT);
	}

	/**
	 * 设置分析结果输出目录
	 * 
	 * @param output
	 */
	public void setOutput(String output) {
		this.properties.put(OUTPUT, output);
	}

	/**
	 * 对于输入分析的日志采用什么符号作为分隔符
	 * 
	 * @return 分隔符
	 */
	public String getSplitRegex() {
		if (this.properties.containsKey(SPLITREGEX))
			return (String) this.properties.get(SPLITREGEX);
		return ",";
	}

	/**
	 * 设置分隔符
	 * 
	 * @param splitRegex
	 */
	public void setSplitRegex(String splitRegex) {
		this.properties.put(SPLITREGEX, splitRegex);
	}

	/**
	 * 日志文件的编码方式
	 * 
	 * @return 编码方式
	 */
	public String getInputEncoding() {
		if (this.properties.containsKey(INPUT_ENCODING))
			return (String) this.properties.get(INPUT_ENCODING);
		return "UTF-8";
	}

	/**
	 * 设置日志文件的编码方式
	 * 
	 * @param inputEncoding
	 */
	public void setInputEncoding(String inputEncoding) {
		this.properties.put(INPUT_ENCODING, inputEncoding);
	}

	/**
	 * 输出文件的编码方式
	 * 
	 * @return 输出文件的编码方式
	 */
	public String getOutputEncoding() {
		if (this.properties.containsKey(OUTPUT_ENCODING))
			return (String) this.properties.get(OUTPUT_ENCODING);
		return "UTF-8";
	}

	/**
	 * 设置输出文件的编码方式
	 * 
	 * @param outputEncoding
	 */
	public void setOutputEncoding(String outputEncoding) {
		this.properties.put(OUTPUT_ENCODING, outputEncoding);
	}

	/**
	 * 输入附加参数
	 * 
	 * @return 输入附加参数
	 */
	public String getInputParams() {
		return (String) this.properties.get(INPUT_PARAMS);
	}

	/**
	 * 设置输入附加参数
	 * 
	 * @param inputParams
	 */
	public void setInputParams(String inputParams) {
		this.properties.put(INPUT_PARAMS, inputParams);
	}

	/**
	 * 输出附加参数
	 * 
	 * @return 输出附加参数
	 */
	public String getOutputParams() {
		return (String) this.properties.get(OUTPUT_PARAMS);
	}

	/**
	 * 设置输出附加参数
	 * 
	 * @param outputParams
	 */
	public void setOutputParams(String outputParams) {
		this.properties.put(OUTPUT_PARAMS, outputParams);
	}
}
